<%@ page contentType="text/html;charset=UTF-8"%>
 <%@page import="com.augurit.common.system.web.auth.form.LoginUserForm"%>
 <%LoginUserForm form=(LoginUserForm)request.getSession().getAttribute("SES_LOGIN_USER"); %>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="wf" uri="/augurit-wf"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- dwr libs -->
<script type='text/javascript' src="${ctx}/dwr/engine.js"></script>
<script type='text/javascript' src="${ctx}/dwr/util.js"></script>
<script type='text/javascript' src="${ctx}/dwr/interface/FileUploadCntl.js"></script>

<script src="${ctx}/gzcgwsp/resources/js/YwUtil.js" type="text/javascript"></script>
<link href="${ctx}/gzcgwsp/resources/css/common-ui.css" rel="stylesheet" type="text/css" />

<script src="${ctx}/gzcgwsp/resources/js/YwEnterprise.js" type="text/javascript"></script>
<script src="${ctx}/gzcgwsp/rqqyjyxk/YwRqQyjyxk/js/gdOtherInfoDataView.js" type="text/javascript"></script>
<script src="${ctx}/gzcgwsp/resources/js/shljysba.js" type="text/javascript"></script>
<script src="${ctx}/gzcgwsp/shljys/js/shljsyba.js" type="text/javascript"></script>
<script src="${ctx}/gzcgwsp/shljys/js/baGrid.js" type="text/javascript"></script>
<script type="text/javascript">
var saveAndSendFlag = undefined;

$(document).ready(function(){
  $('form[0]').ajaxForm({
    dataType: 'json', 
    success: wfBusSaveCallback
  });
  $("input[type='text']").each(function(i){
		$(this).addClass("text"); 
 	});
 	
	 $("textarea").each(function(i){
  		$(this).addClass("inputArea"); 
 	});
});

function wfBusSaveCallback(result){
	var success = window.updateLayoutAfterWfBusSave(result, false);
	
    if (!result.success) return;
    
	if(success){
		document.forms[0].id.value = result.form.id;
		document.forms[0].qybh.value = result.form.qybh;
		document.forms[0].acceptNo.value = result.form.acceptNo;
		document.getElementById('sjcl_iframe').src = '${ctx}/yw-com-sjcllist!ywList.action?tplcode=${templateCode}&ajid=' + result.form.id + '&qyid=' + result.form.qybh;
      	if (Ext.getCmp('sjclPanel')) Ext.getCmp('sjclPanel').setDisabled(false);
	}

    if(saveAndSendFlag == 'wfBusSaveAndSend') {
        var toolbar = Ext.getCmp('WF_TOOLBAR');
        if(toolbar)
			toolbar.wfSend();
	}else
		alert('保存成功！');
}

Ext.onReady(function(){
    var id_ = document.forms[0].id.value;
    //var acceptNo_ = document.forms[0].acceptNo.value;
    
     if (id_ == '') {
        if (Ext.getCmp('WF_PRINT')) Ext.getCmp('WF_PRINT').setDisabled(true);
     }
      var centerTabPanel = Ext.getCmp('centerPanel');
      var ywPanel = new Ext.TabPanel({
        id: 'YwHwShSqbTpanel',
        renderTo: 'tpanel',
        activeTab:3,
        border: false,
        height: centerTabPanel.getHeight(),
        enableTabScroll: true,
        defaults: {autoScroll: true},
        items: [
        ],
        listeners: {
            remove: function(tp, c) {
                c.hide();
            },
            afterlayout: function(c) {
                c.strip.setWidth(c.stripWrap.getWidth() - 2);
            },
            tabchange : function (tpanel, p) { }
        }
    });
         
    var jbxxPanel = new Ext.Panel({title: '基本信息', tabCls: 'right-tab', contentEl: 'tpanel01', border: false});
    var cpbPanel = new Ext.Panel({title: '呈批表', tabCls: 'right-tab', contentEl: 'tpanel02', border: false});
    ywPanel.add(new Ext.Panel({id: 'sjclPanel', title: '收件材料', tabCls: 'right-tab', contentEl: 'sjcl_tpanel', border: false, disabled: id_ == '' ? true : false}));
    ywPanel.add(jbxxPanel);
    if (!<wf:hasPriv activities="cksa" />) {
        ywPanel.add(cpbPanel); 
        ywPanel.setActiveTab(cpbPanel);   
    }else{
        ywPanel.setActiveTab(jbxxPanel);
    }
    ywPanel.doLayout(true);
    
    if (<wf:hasPriv activities="xyzxjbr,syzxld,jbrsj,czdjgz" />) {
        ywPanel.add(cpbPanel);
        ywPanel.setActiveTab(cpbPanel);
    } else {
        ywPanel.setActiveTab(jbxxPanel);
    }
    ywPanel.doLayout(true);
});


/**
 * 全选/全不选函数
 * @param checkboxName 需要被设置的checkbox或checkbox数组控件的name属性所指定的名称
 * @param checkallObj 全选checkbox控件元素
 */
function checkAll(checkboxName, checkallObj){
    var ids = document.getElementsByName(checkboxName);
    if(ids != null){
        var ischeckall = checkallObj.checked;   
        //如果ids为一项checkbox
        if(ids.type == "checkbox"){
            ids.checked = ischeckall;
            return;
        }
        //如果ids为checkbox数组
        for(var i=0; i<ids.length; i++){
            ids[i].checked = ischeckall;
        }
    }
}



function importData(){
	 	//窗口收案
    Ext.MessageBox.confirm("请确认","确定要将收件材料导入企业信息中吗？",function(button,text){  
          if(button=="yes") {
              checkImportData();
          }else{
              return;
          }
            
     });
}

//窗口收案导入前数据检查
function checkImportData(){
    var id=document.getElementById("id").value;
     var myMask= waiteWin();
     var url="${ctx}/shlj-ys-ba!checkImportData.action";
     myMask.show();
     Ext.Ajax.request({
     url:url,
     params:{id:id,templateCode:"${templateCode}"},
     method:'POST',
     success:function(response){
         myMask.hide();
         var result=response.responseText;
         if(result=="dataNotExist"){
              Ext.Msg.alert("提示","收件材料中申请表没有上传或上传的格式错误");
                  return;
         }else if(result=="exist"){
             Ext.MessageBox.confirm("请确认","此企业信息已经存在，确认导入吗？",function(button,text){  
                 if(button=="yes")   
                     importqyData();
                 else
                   return;
            });
         }else{
               if(result!=null && result!="" && result!="null"){
         		 alert("导入的数据在其他信息中存在!");
         		document.getElementById("checkdata").value=result;
         		var actionUrl="${ctx}/smart-form-shljqs!showCheckData.action";
         		 YwUtil.openWin({url: actionUrl, w: 800, h: 550});
	         	 if(confirm("导入的数据在其他信息中存在,确认要继续导入吗?")) {
	         	 	importqyData();
	         	 }else{
	         	 	return;
	         	 }
         	}else{
         		importqyData();
         	}
         }
       
    },
    failure: function() {
        Ext.Msg.alert('错误', '请求失败,请稍后重试'); 
        myMask.hide();
     } 
 });
}

//窗口收案导入
function importqyData(){
    var id=document.getElementById("id").value;
    var qybh = document.getElementById("qybh").value;
    var myMask= waiteWin();
    var url="${ctx}/shlj-ys-ba!importData.action";
    myMask.show();
    Ext.Ajax.request({
    url:url,
    params:{id:id,templateCode:"${templateCode}",qybh:qybh},
    method:'POST',
    success:function(response){
        myMask.hide();
        var result=response.responseText;
        if(result==""){
            Ext.Msg.alert("提示信息","数据导入成功",function(){
            
            });
        }else{
               Ext.Msg.alert("提示信息",result);
        }
     
   },
   failure: function() {
       Ext.Msg.alert('错误', '请求失败,请稍后重试'); 
       myMask.hide();
    } 
});
}


function waiteWin(){
    var wait = new Ext.LoadMask(Ext.getBody(), {msg:"请稍后..."}); 
    return wait;
}

//查看原来已结信息
function showHistory(){
    var syysid=document.getElementById("syysid").value;
    var url='${ctx}/shlj-ys-ba!getYjInfo.action?type=sy&syysid='+syysid
	selectInfo(url);	
}


function setQyInfo(){
  selectShljysbaQyxx('${templateCode}');
}

function wfBusSaveAndSend(templateCode, taskInstDbid){
  saveAndSendFlag = 'wfBusSaveAndSend';
  if(validateSend()){
    $('form[0]').attr('action', '${ctx}/shlj-ys-ba!wfBusSave.action?templateCode='+templateCode+'&taskInstDbid='+taskInstDbid);
    $('form[0]').submit();
  }
}

function wfBusSave(templateCode, taskInstDbid){
  saveAndSendFlag = 'wfBusSave';
  if(validateForm()){
    $('form[0]').attr('action', '${ctx}/shlj-ys-ba!wfBusSave.action?templateCode='+templateCode+'&taskInstDbid='+taskInstDbid);
    $('form[0]').submit();
  }
}

function saveOpinion() {
    var syzxldTxt = document.getElementById('syzxldJudgmentTxt');
    var jbhcTxt = document.getElementById('jbhcJudgmentTxt_ynczz');
    
    
    var inputObj, divobj;
    if (syzxldTxt && !jbhcTxt) {
      inputObj = syzxldTxt; divobj = document.getElementById('syzxldJudgment');
    } else if (!syzxldTxt && jbhcTxt) {
      inputObj = jbhcTxt; divobj = document.getElementById('jbhcJudgment');
    }
    
    
    if (!inputObj || inputObj.value == '') return;
    
    Ext.Ajax.request({
      method:'post',
      url:'${ctx}/wf!saveTaskOpinion.action',
      params:{
        'instance.taskInstDbid': WF_CONFIG.taskInstDbid,
        'instance.handleComments': inputObj.value
      },
      success:function(){
      changeOpinion(inputobj.value, divobj);
        inputobj.value = '';
      },
      scope:this
    });
}

function inputJudgment(index) {
    var divid = '', inputid = '';
    switch(index) {
        case 'A': divid = 'jbhcJudgment'; inputid = 'jbhcJudgmentTxt_ynczz'; break;
        case 'B': divid = 'syzxldJudgment'; inputid = 'syzxldJudgmentTxt'; break;
    }
    var divobj = document.getElementById(divid);
    var inputobj = document.getElementById(inputid);
    if (divid == '' || !divobj) {
        alert('参数错误！');
        return;
    }
    if (inputobj.value == '') { alert('请输入意见!'); return; }
    Ext.Ajax.request({
      method:'post',
      url:'${ctx}/wf!saveTaskOpinion.action',
      params:{
        'instance.taskInstDbid': WF_CONFIG.taskInstDbid,
        'instance.handleComments': inputobj.value
      },
      success:function(){
        changeOpinion(inputobj.value, divobj);
        inputobj.value = '';
      },
      scope:this
    });
}

function changeOpinion(opinion, divobj) {
  var userOpinion = document.getElementById('userOpinion');
  if (userOpinion) {
    userOpinion.innerHTML = opinion + '<br>&nbsp;&nbsp;&nbsp;&nbsp;${CurrUserName}&nbsp;&nbsp;' + new Date().format('yyyy-MM-dd hh:mm:ss');
  } else {
    divobj.style.color = '#009966';
    divobj.innerHTML = opinion + '<br>&nbsp;&nbsp;&nbsp;&nbsp;${CurrUserName}&nbsp;&nbsp;' + new Date().format('yyyy-MM-dd hh:mm:ss');
  }
}


function writeJudgment(index) {
    var divid = '';
    switch(index) {
        case 'A': divid = 'jbhcJudgment'; break;
        case 'B': divid = 'syzxldJudgment'; break;
    }
    var divobj = document.getElementById(divid);
    if (divid == '' || !divobj) {
        alert('参数错误！');
        return;
    }
    var win = new Ext.ux.wf.WfOpinionWin({
        taskInstDbid: Ext.getCmp('WF_TOOLBAR').taskInstDbid
    });
    win.show();
    win.on('complete', function (opinion) {
        divobj.innerHTML = opinion + '<br>&nbsp;&nbsp;&nbsp;&nbsp;${CurrUserName}&nbsp;&nbsp;' + new Date().format('yyyy-MM-dd hh:mm:ss');
    });
}

//打印证书
function printxkz(){
	var id = document.forms[0].id.value;
	openCenterWindow(ctx + '/shlj-ys-ba!preViewXkz.action?id='+id+"&taskId="+parent.WF_CONFIG.taskInstDbid, 1100, 650);
}

function printxkzFb(){
  	var id = document.forms[0].id.value;
  	openCenterWindow(ctx + '/shlj-ys-ba!printViewFb.action?id='+id+"&taskId="+parent.WF_CONFIG.taskInstDbid, 1100, 650);
}

</script>

</head>
<body>
 
<form action="yw-rq-qyjyxkgd!save.action" method="post">
  <!---------------- 隐藏域区域 开始 ----------------->
  <input type="hidden" id="id" name="id" value="${id}" />
   <input type="hidden" id="checkdata"/>
   <input type="hidden" name="syysid" id="syysid" value="${syysid}" />
   <input type="hidden" id="qybh" name="qybh" value="${qybh}" />
   <input type="hidden" id="username"/>
  <!--<input type="hidden" id="templateCode" name="templateCode" value="${templateCode}" /> --> 
  <!---------------- 隐藏域区域 结束 ----------------->  
<div id="tpanel"></div>
<div style="display:none">
	<div id="tpanel01" align="center">
	<%@ include file="syshljbasqb.jsp" %>
	</div>
	<div id="tpanel02" align="center">
	     <%@ include file="syshljbacpb.jsp" %>
	</div>
	<div id="gis_tpanel">
        <iframe src="${ctx}/flex/index.html" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>
     </div>
    <div id="sjcl_tpanel">
        <iframe id="sjcl_iframe" name="sjcl_iframe" src="${ctx}/yw-com-sjcllist!ywList.action?tplcode=${templateCode}&ajid=${id}&qyid=${qybh}" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>
    </div>
</div>
</form>

<div style="display:none">
  <input id="attacheBrow" type="file" />
</div>
</body>
</html>
